package com.losdun.product.controller.app;

import com.losdun.common.annotation.Anonymous;
import com.losdun.common.core.controller.BaseController;
import com.losdun.common.core.domain.AjaxResult;
import com.losdun.product.domain.Category;
import com.losdun.product.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 产品分类Controller
 * 
 * @author sword.ye
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/app/product/category")
public class AppCategoryController extends BaseController
{
    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询产品分类列表
     */
    @Anonymous
    @GetMapping("/list")
    public AjaxResult list(Category category)
    {
        List<Category> list = categoryService.selectCategoryList(category);
        list.forEach(cate->{
            if(cate.getPrice()==null){
                cate.setMinPrice(categoryService.getCategoryMinPrice(cate.getId()));
            }
        });
        return success(list);
    }

}
